
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<head>
<script src="/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">

function hideSuggest(){
	$(".suggestList").hide();
}

function getSuggest(keyword){
	// 回车即搜索
	if (event.keyCode==13){
		doSearch(keyword);
	}
	
	var url = "http://127.0.0.1:8080/suggest.do?keyword=" + keyword +"&callback=?";
	jQuery.getJSON(url, function(data){
		var suggests = data.suggestlist;
		if (suggests && suggests.length!=0) {
			var sugHtml = "";
			for (i=0; i<suggests.length; i++) {
				sugHtml += "<a href='javascript:void(0);' onmousedown='doSearch(\""+suggests[i].key +"\")'>" + suggests[i].key +"</a>";
			}
			$(".suggestList").html(sugHtml).show();
		}
	});
}

function doSearch(keyword){
	var url = "/search.do?keyword=" + keyword;
	window.location.href=url;
}

$(document).ready(function(){
	init_check_box();
	init_radio();
	$("#search_button").click(function(){
		doSearch($("#keyword").val());
	});
	
	$(".sourcecode").click(function(){
		var url = "/search_detail.do?uid=" + $(this).attr("uid");
		window.location.href=url;
	});
	
	
	$(".div_left :checkbox").click(function(){
		var originUrl = window.location.href;
		var url = "/search.do?keyword=" + '<s:property value="keyword"/>';
		
		// Project name parameter
		var fp = "";
		var hasProject = false;
		$(".facet_project").each(function(){
			if ($(this).prop("checked") == true) {
				hasProject = true;
			}
		  	var element = "&fp=" + $(this).attr("name") + "," + $(this).attr("value") + "," + $(this).prop("checked");
		  	fp += element;
		});
		if (hasProject) {
			url += fp;	
		}
		
		// File type parameter
		var ff = "";
		var hasFileType = false;
		$(".facet_filetype").each(function(){
			if ($(this).prop("checked") == true) {
				hasFileType = true;
			}
			var element = "&ff=" + $(this).attr("name") + "," + $(this).attr("value") + "," + $(this).prop("checked");
			ff += element;
		});
		if (hasFileType) {
			url += ff;
		}
		
		window.location.href=url;
	});
	
});

function init_check_box(){
	<s:iterator value="projectAttr.itemList" id="item">
		<s:if test="%{#item.checked}">
			$("input[name='<s:property value="#item.label"/>']").prop("checked", true);
		</s:if>
	</s:iterator>
	
	<s:iterator value="fileTypeAttr.itemList" id="item">
	<s:if test="%{#item.checked}">
		$("input[name='<s:property value="#item.label"/>']").prop("checked", true);
	</s:if>
</s:iterator>
}

function init_radio(){
	$(".sortBy :radio[value='<s:property value="sortBy"/>']").prop("checked", true);
}

function goPage(page){
	var originUrl = window.location.href;
	var st = originUrl.indexOf("pageNo");
	if (st != -1) {
		var left = originUrl.substring(0, st-1);
		var right = originUrl.substring(st);
		var last = right.indexOf("&");
		if (last != -1) {
			originUrl = left + right.substring(last);
		} else {
			originUrl = left;			
		}
	}
	var url = originUrl + "&pageNo=" + page;
	//alert(url);
	window.location.href = url;
}

function sort(sortBy){
	var originUrl = window.location.href;
	var st = originUrl.indexOf("sortBy");
	if (st != -1) {
		var left = originUrl.substring(0, st-1);
		var right = originUrl.substring(st);
		var last = right.indexOf("&");
		if (last != -1) {
			originUrl = left + right.substring(last);
		} else {
			originUrl = left;			
		}
	}
	var url = originUrl + "&sortBy=" + sortBy;
	//alert(url);
	window.location.href = url;
}

</script>
<style type="text/css">
/* Paging begin */
.pagination_top {
    float: left;
    margin-left: 80px;
    
}

.pagination_top a, .pagination a:link, .pagination a:visited {
    padding: 2px 5px 2px 5px;
    margin: 2px;
    border: 1px solid #aaaadd;
    text-decoration: none;
    color: #006699;
}


.pagination {
    padding: 5px;
    float: right;
    padding: 10px 85px 10px;
}

.pagination a, .pagination a:link, .pagination a:visited {
    padding: 2px 5px 2px 5px;
    margin: 2px;
    border: 1px solid #aaaadd;
    text-decoration: none;
    color: #006699;
}

.pagination a:hover, .pagination a:active {
    border: 1px solid #006699;
    color: #000;
    text-decoration: none;
}

.pagination span.current {
    padding: 2px 5px 2px 5px;
    margin: 2px;
    border: 1px solid #006699;
    font-weight: bold;
    background-color: #006699;
    color: #FFF;
}
/* Paging end */

/* 左侧facet begin */
.div_left{float:left;width:200px;height:auto!important;height:100px;
	background-color:#FFFFFF; padding-left: 8px;}
.div_left input{margin-bottom: 8px;}
.div_left a:hover, .div_left a:active {
    border: 1px solid #006699;
    color: #000;
    text-decoration: none;
    cursor: text;
}
.div_left a, .div_left a:link, .div_left a:visited {
    padding: 2px 5px 2px 5px;
    margin: 2px;
    text-decoration: none;
    color: #000;
    cursor: text;
}
.div_left .facet_attr{
	display:inline-block;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;
	width:180px; margin-bottom: 4px;
}
.facet_attr a:hover{
    content: attr(title);
}
.facet_title{
	margin: 5px;
	display: block;;
}
/* 左侧facet end */

.div_right{float:right;width:120px;height:auto!important;height:100px;background-color:#FFFFFF;}
.div_middle{margin:0px 120px 0px 200px;background-color:#FFFFFF;}

/* 过滤 & 统计 */
.sortBy{width:300px;float:left;left:-80px}
.statistics{margin-left:100px;float: left;text-align: center; width: 350px;}

/* 代码摘要begin */
.source{background-color: #eee; margin: 0px 10px 7px 10px;font-family: Consolas,monospace;}
.sourcecode h4{color: #447be8;font-family: Helvetica,Arial,sans-serif;
font-size: 110%;padding: 0px 0px 0px 0px; margin: 6px 6px 6px 10px;}
.sourcecode .updatetime{font-family: Helvetica,Arial,sans-serif;font-size: smaller; 
	margin-left: 10px; margin-top: 0px;}
.sourcecode{border: 1px solid #fff; margin: 4px 0px 10px 0;}
.sourcecode:hover{border: 1px solid #eee; background-color: #ffffe0}
/* 代码摘要end */

.div_search {margin-right:auto; margin-left:auto;width: 500px; height: 50px;}
/* 下拉列表begin */
*{margin:0;padding:0;}
.suggestList{
    font-size:12px;
    position:relative;
    z-index:100;
    background-color: #FFFFFF;
    width: 400px;;
    display: none;
}    
.suggestList a{display:block;border:1px solid; background:#fff;padding:3px 1px;
	margin:3px;color:#000;text-decoration:none;}   
.suggestList a{display:block;width:400px;height:13px;margin:0;border:0;border-bottom:1px #eee;}   
.suggestList a:hover{border:0;background:#eee;border-bottom:1px solid #fff;}
/* 下拉列表end */
</style>
</head>


<body>

<div class="div_search">
<input type="text" id="keyword" value="<s:property value="keyword"/>" style="width: 400px;"
	onblur="hideSuggest();" onkeyup="getSuggest($(this).val());"/>
<input type="button" id="search_button" value="搜索"/>
<div class="suggestList">  
		<a href="CN Tool_Kacey_v3_201201.xls">Jan</a>
</div>
</div>
<!-- 左侧facet begin -->
<div class="div_left">
	<!-- Attribute project begin -->
	<div style="margin-bottom: 30px;">
	<s:if test="projectAttr.itemList.size() gt 0">
		<span class="facet_title">项目:<br></span>
		<s:iterator value="projectAttr.itemList" id="item">
			<div class="facet_attr">
			<a href="javascript:void(0)" title='<s:property value="#item.label"/>(<s:property value="#item.value"/>)'>
			<input class="facet_project" type="checkbox" name='<s:property value="#item.label"/>'
				value='<s:property value="#item.value"/>'/>
				<s:property value="#item.label"/>(<s:property value="#item.value"/>)<br>
			</a>
			</div>
		</s:iterator>
	</s:if>
	<s:else>
		<span class="facet_title">项目:<br></span>
		<s:iterator value="result.facetResults.projectName.nodes" id="node">
			<div class="facet_attr">
			<a href="javascript:void(0)" title='<s:property value="#node.label"/>(<s:property value="#node.value"/>)'>
				<input class="facet_project" type="checkbox" name='<s:property value="#node.label"/>'
					value='<s:property value="#node.value"/>'/>
				<s:property value="#node.label"/>(<s:property value="#node.value"/>)<br>
			</a>
			</div>
		</s:iterator>
	</s:else>
	</div>
	<!-- Attribute project end -->
	
	<!-- Attribute file type begin -->
	<s:if test="fileTypeAttr.itemList.size() gt 0">
		<span class="facet_title">文件类型:<br></span>
		<s:iterator value="fileTypeAttr.itemList" id="item">
		<div class="facet_attr">
			<a href="javascript:void(0)" title='<s:property value="#item.label"/>(<s:property value="#item.value"/>)'>
			<input class="facet_filetype" type="checkbox" name='<s:property value="#item.label"/>'
				value="<s:property value="#item.value"/>"/>
			<s:property value="#item.label"/>(<s:property value="#item.value"/>)<br>
			</a>
		</div>
		</s:iterator>
	</s:if>
	<s:else>
		<span class="facet_title">文件类型:<br></span>
		<s:iterator value="result.facetResults.fileType.nodes" id="node">
		<div class="facet_attr">
			<a href="javascript:void(0)" title='<s:property value="#node.label"/>(<s:property value="#node.value"/>)'>
			<input class="facet_filetype" type="checkbox" name='<s:property value="#node.label"/>'
				value="<s:property value="#node.value"/>"/>
			<s:property value="#node.label"/>(<s:property value="#node.value"/>)<br>
			</a>
		</div>
		</s:iterator>
	</s:else>
	<!-- Attribute file type end -->
</div>
<!-- 左侧facet end -->

<div class="div_middle">
<!-- 顶部搜索、统计、翻页 begin -->
	<div style="display: inline-block; margin-bottom: 10px;">
	<div class="sortBy">
	<input type="radio" value="0" id="sortBy" name="sortBy" onclick="sort(0)">按匹配程度
	<input type="radio" value="1" id="sortBy" name="sortBy" onclick="sort(1)">按提交时间
	</div>

	<div class="statistics">
		<%-- Results <s:property value="result.currentPage*10 + 1" /> - <s:property value="result.currentPage*10 + 10" /> 
		of about <s:property value="result.total" /> results found for '<s:property value="keyword" />'. --%>
		共查询结果 【<s:property value="result.total" />】 条，当前第
		<s:property value="result.currentPage*10 + 1" /> - 
		<s:if test="result.currentPage*10 + 10 lt result.total">
			<s:property value="result.currentPage*10 + 10" />
		</s:if>
		<s:else>
			<s:property value="result.total" />
		</s:else>
		 
		条
	</div>
	
	<!-- 上方翻页条 -->
	<div class='pagination_top'>
		<s:if test="result.currentPage==0">
		   	<span class='disabled'> 上一页</span>
		</s:if>
		<s:else>
			<a href="javascript:void(0)" onclick="goPage('<s:property value="result.currentPage"/>'-1)"> 上一页</a>
		</s:else>
		<s:property value="result.currentPage+1"/>
		<s:if test="result.currentPage+1==result.totalPage">
		   	<span class='disabled' onclick="javascript:void(0)"> 下一页</span>
		</s:if>
		<s:else>
			<a href="javascript:void(0)" onclick="goPage(parseInt('<s:property value="result.currentPage"/>')+1)"> 下一页</a>
		</s:else>
	</div>
</div>
<!-- 顶部搜索、统计、翻页 end -->

<!-- 代码摘要列表 begin -->
<s:iterator value="result.sources" id="source">
<div class="sourcecode" uid="<s:property value="#source.uid" />">
	<h4 class="title"><s:property escape="false" value="#source.title" /></h4>
	<div class="source">
	<s:property escape="false" value="#source.fregment"/>
	</div>
	<p class="updatetime">
		最近更新时间：<s:property escape="false" value="#source.lastUpdateTime"/>
	</p>
</div>
</s:iterator>
<!-- 代码摘要列表 end -->
</div>

<!-- 下方翻页条 -->
<%@ include file="paging.jsp" %>

</body>
